package com.xd.core.finance.controller;


import com.github.pagehelper.Page;
import com.xd.core.company.mapper.CompanyMapper;
import com.xd.core.finance.dto.ConsumeDetailQuery;
import com.xd.core.finance.dto.RechargeRecordQuery;
import com.xd.core.finance.entity.ConsumeDetail;
import com.xd.core.finance.entity.RechargeRecord;
import com.xd.core.finance.service.IRechargeRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 * 充值记录表 前端控制器
 * </p>
 *
 * @author ZX
 * @since 2025-03-31
 */
@Api(tags = "充值记录")
@RestController
@RequestMapping("/finance/recharge-record")
public class RechargeRecordController {
    @Autowired
    private IRechargeRecordService iRechargeRecordService;
    @Autowired
    private CompanyMapper companyMapper;

    @PreAuthorize("hasAnyAuthority('sys:ServiceFee-viewDetails')")
    @ApiOperation("服务费消充值列表")
    @PostMapping("/getList")
    public Page<RechargeRecord> getList(@RequestBody RechargeRecordQuery query) {
        return iRechargeRecordService.getList(query);
    }
    @PreAuthorize("hasAnyAuthority('sys:AssetManagement-Recharge','sys:GroupCompanyRecharge')")
    @ApiOperation("服务费充值按钮")
    @PostMapping("/Recharge")
    public void insertRecharge (@RequestBody RechargeRecord rechargeRecord){
        iRechargeRecordService.insertRecharge(rechargeRecord);
    }

    @PreAuthorize("hasAnyAuthority('sys:AssetManagement-Refund','sys:GroupCompanyRefund')")
    @ApiOperation("退款按钮")
    @PostMapping("/refund")
    public void refund (@RequestBody RechargeRecord rechargeRecord){
        iRechargeRecordService.refund(rechargeRecord);
    }

    @ApiOperation("服务费余额")
    @PostMapping("/getBalance/{companyId}")
    public BigDecimal getBalance(@PathVariable Integer companyId) {
        return companyMapper.selectBalance(companyId);
    }
}
